require(["jquery","bbcare",
        "scprit/evaluatingPublicPages/vm/nbna/nbnaAssessment.ui.js",
        "scprit/evaluatingPublicPages/vm/nbna/assessQuestion.servers.js",
        "scprit/evaluatingPublicPages/vm/nbna/nbnaAssessment.event.js"],
    function ($,$bb,$ui,$servers,$event) {
        var getParams = JSON.parse($bb.getSessionStorage('nbna'));
        sessionStorage.removeItem('nbna');
        //请求问卷内容：
        var ajaxData = function(getParams,lastScore){
            $bb.ajax({
                url: "scprit/department/data/nbna/nbna.json",
                success: function (data) {
                    if(data.success){
                        var scoreObj={};
                        if(lastScore && lastScore.answerId){
                            scoreObj = JSON.parse(lastScore.answerResult).map;
                            $event.countTotalScore(scoreObj);
                        }
                        var itemArr = ["行为能力","被动肌张力","主动肌张力","原始反射","一般反应"];
                        data = data.data;
                        var tabs = $event.tabs(data,scoreObj);
                        $ui.tabsInit({"id":"#tabs","data":tabs});
                        $event.dataDeal(data,scoreObj);
                        $event.tabClick(data);
                        $event.quesClick(data);
                        $event.optionsClick(data,scoreObj,itemArr);
                        $('#tabs>li[class*="checked"]').click();
                        $event.submitBtn(scoreObj,getParams);
                    }
                }
            });
        };
        //获取最后一次历史记录：
        var historyParams = $servers.hisParams(getParams);
        var callback = function(data,params){
            if(data.success){
                var lastScore = data.rows.length > 0 ? data.rows[0] : null;
                ajaxData(params,lastScore);
            }else{
                $bb.toastShow(data.msg ? data.msg : "查询评估记录出错！");
            }
        };
        $servers.history(historyParams,callback,getParams);
    });